home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / driverss.zip / NE1000.ASM < prev    next >
Assembly Source File  |  1991-03-19  |  7KB  |  288 lines

  1. version    equ    5
  2. ;History:261,1
  3.  
  4. ;  Russell Nelson, Clarkson University.
  5. ;  Copyright, 1988-1991, Russell Nelson
  6. ;  The following people have contributed to this code: David Horne, Eric
  7. ;  Henderson, and Bob Clements.
  8.  
  9. ;   This program is free software; you can redistribute it and/or modify
  10. ;   it under the terms of the GNU General Public License as published by
  11. ;   the Free Software Foundation, version 1.
  12. ;
  13. ;   This program is distributed in the hope that it will be useful,
  14. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ;   GNU General Public License for more details.
  17. ;
  18. ;   You should have received a copy of the GNU General Public License
  19. ;   along with this program; if not, write to the Free Software
  20. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.  
  23.     include    defs.asm
  24.  
  25. code    segment    word public
  26.     assume    cs:code, ds:code
  27.  
  28. ;*****************************************************************************
  29. ;
  30. ;    NE1000 controller board offsets
  31. ;    IO port definition (BASE in io_addr)
  32. ;*****************************************************************************
  33. NE_DATAPORT    EQU    10h        ; NE1000 Port Window.
  34. NE_RESET    EQU    1fh        ; Issue a read for reset
  35. EN_OFF        equ    0h
  36.  
  37.     include    8390.inc
  38.  
  39. ; Shared memory management parameters
  40.  
  41. SM_TSTART_PG    EQU    20h        ; First page of TX buffer
  42. SM_RSTART_PG    EQU    26h        ; start at page 26
  43. SM_RSTOP_PG    EQU    40h        ; end at page 40
  44.  
  45. pause_    macro
  46. ;    jmp    $+2
  47. endm
  48.  
  49. longpause macro
  50.     push    cx
  51.     mov    cx,0
  52.     loop    $
  53.     pop    cx
  54. endm
  55.  
  56. ram_enable    macro
  57.     endm
  58.  
  59. reset_8390    macro
  60.     loadport
  61.     setport    NE_RESET
  62.     in    al,dx
  63.     longpause
  64.     out    dx,al        ; should set command 21, 80
  65.     longpause
  66.     endm
  67.  
  68. terminate_board    macro
  69.     endm
  70.  
  71.     public    int_no, io_addr
  72. int_no        db    3,0,0,0        ;must be four bytes long for get_number.
  73. io_addr        dw    0300h,0        ; I/O address for card (jumpers)
  74.  
  75.     public    driver_class, driver_type, driver_name, driver_function, parameter_list
  76. driver_class    db    BLUEBOOK, IEEE8023, 0        ;from the packet spec
  77. driver_type    dw    53        ;from the packet spec
  78. driver_name    db    'NE1000',0    ;name of the driver.
  79. driver_function    db    2
  80. parameter_list    label    byte
  81.     db    1    ;major rev of packet driver
  82.     db    9    ;minor rev of packet driver
  83.     db    14    ;length of parameter list
  84.     db    EADDR_LEN    ;length of MAC-layer address
  85.     dw    GIANT    ;MTU, including MAC headers
  86.     dw    MAX_MULTICAST * EADDR_LEN    ;buffer size of multicast addrs
  87.     dw    0    ;(# of back-to-back MTU rcvs) - 1
  88.     dw    0    ;(# of successive xmits) - 1
  89. int_num    dw    0    ;Interrupt # to hook for post-EOI
  90.             ;processing, 0 == none,
  91.  
  92. is_186        db    0
  93.  
  94. ;
  95. ;    Special case Block input routine. Used on extra memory
  96. ;    space for board ID etc. DMA count is set X2,
  97. ;    CX = byte count, es:si = buffer location, ax = buffer address
  98. ;
  99. sp_block_input:
  100. ;    Nothing special needed for NE-1000.
  101. ;
  102. ;    Block input routine
  103. ;    CX = byte count, es:di = buffer location, ax = buffer address
  104.  
  105.     public    block_input
  106. block_input:
  107.     push    ax        ; save buffer address
  108.     loadport
  109.     setport EN_CCMD
  110.     pause_
  111.     mov    al,ENC_NODMA+ENC_PAGE0+ENC_START
  112.     out    dx,al
  113.     mov    ax,cx            ;get the count to be output.
  114.     setport    EN0_RCNTLO    ; remote byte count 0
  115.     pause_
  116.     out    dx,al
  117.     setport    EN0_RCNTHI
  118.     pause_
  119.     mov    al,ah
  120.     out    dx,al
  121.     pop    ax        ; get our page back
  122.     setport    EN0_RSARLO
  123.     pause_
  124.     out    dx,al        ; set as hi address
  125.     setport    EN0_RSARHI
  126.     pause_
  127.     mov    al,ah
  128.     out    dx,al
  129.     setport EN_CCMD
  130.     pause_
  131.     mov    al,ENC_RREAD+ENC_START    ; read and start
  132.     out    dx,al
  133.     setport    NE_DATAPORT
  134.     pause_
  135.     cmp    is_186,0
  136.     jnz    read_186
  137. read_loop:
  138.     in    al,dx        ; get a byte
  139.     stosb            ; save it
  140.     loop    read_loop
  141.     ret
  142. read_186:
  143.     db    0f3h, 06ch    ;masm 4.0 doesn't grok "rep insb"
  144.     ret
  145. ;
  146. ;    Block output routine
  147. ;    CX = byte count, ds:si = buffer location, ax = buffer address
  148.  
  149. block_output:
  150.     assume    ds:nothing
  151.     push    ax        ; save buffer address
  152.     inc    cx        ; make even
  153.     and    cx,0fffeh
  154.     loadport
  155.     setport EN_CCMD
  156.     pause_
  157.     mov    al,ENC_NODMA+ENC_START
  158.     out    dx,al        ; stop & clear the chip
  159.     setport    EN0_RCNTLO    ; remote byte count 0
  160.     pause_
  161.     mov    al,cl
  162.     out    dx,al
  163.     setport    EN0_RCNTHI
  164.     pause_
  165.     mov    al,ch
  166.     out    dx,al
  167.     pop    ax        ; get our page back
  168.     setport    EN0_RSARLO
  169.     pause_
  170.     out    dx,al        ; set as lo address
  171.     setport    EN0_RSARHI
  172.     pause_
  173.     mov    al,ah
  174.     out    dx,al
  175.     setport EN_CCMD
  176.     pause_
  177.     mov    al,ENC_RWRITE+ENC_START    ; write and start
  178.     out    dx,al
  179.     setport    NE_DATAPORT
  180.     pause_
  181.     cmp    byte ptr is_186,0
  182.     jnz    write_186
  183. write_loop:
  184.     lodsb            ; get a byte
  185.     out    dx,al        ; save it
  186.     loop    write_loop
  187.     jmp    short block_output_1
  188. write_186:
  189.     db    0f3h, 06eh    ;masm 4.0 doesn't grok "rep outsb"
  190. block_output_1:
  191.     mov    cx,0
  192.     setport    EN0_ISR
  193. tx_check_rdc:
  194.     in    al,dx
  195.     test    al,ENISR_RDC    ; dma done ???
  196.     jnz    tx_start
  197.     loop    tx_check_rdc
  198.     stc
  199.     ret
  200. tx_start:
  201.     clc
  202.     ret
  203.  
  204.  
  205.     include    8390.asm
  206.  
  207.     public    usage_msg
  208. usage_msg    db    "usage: NE1000 [-n] [-d] [-w] <packet_int_no> <int_no> <io_addr>",CR,LF,'$'
  209.  
  210.     public    copyright_msg
  211. copyright_msg    db    "Packet driver for NE1000, version "
  212.         db    '0'+majver,".",'0'+version,".",'0'+dp8390_version,CR,LF,'$'
  213.  
  214. cfg_err_msg    db    "NE1000 Configuration failed. Check parameters.",CR,LF,'$'
  215. int_no_name    db    "Interrupt number ",'$'
  216. io_addr_name    db    "I/O port ",'$'
  217.  
  218.     extrn    set_recv_isr: near
  219.  
  220. ;enter with si -> argument string, di -> word to store.
  221. ;if there is no number, don't change the number.
  222.     extrn    get_number: near
  223.  
  224. ;enter with dx -> name of word, di -> dword to print.
  225.     extrn    print_number: near
  226.  
  227.     public    parse_args
  228. parse_args:
  229. ;exit with nc if all went well, cy otherwise.
  230.     mov    di,offset int_no
  231.     call    get_number
  232.     mov    di,offset io_addr
  233.     call    get_number
  234.     clc
  235.     ret
  236.  
  237.     extrn    etopen_diagn: byte
  238.  
  239. bad_addr_msg    label    byte
  240.  db "The Ethernet address of this card is invalid, because it has the",CR,LF
  241.  db "multicast bit set.  We will reset that bit and continue...",CR,LF,'$'
  242.  
  243. init_card:
  244. ;get the board data. This is (16) bytes starting at remote
  245. ;dma address 0. Put it in a buffer called board_data.
  246.  
  247.     mov    cx,10h        ; get 16 bytes,
  248.     push    ds
  249.     pop    es        ; set es to ds
  250.     mov    di,offset board_data
  251.     mov    ax,0        ; from address 0
  252.     call    sp_block_input
  253.  
  254.     push    ds              ; Copy from card's address to current address
  255.     pop     es
  256.  
  257.     test    board_data,1        ;did the fools pick their own id?
  258.     je    init_card_1        ;no.
  259.  
  260.     and    board_data,not 1    ;reset the multicast bit,
  261.     mov    dx,offset bad_addr_msg
  262.     mov    ah,9
  263.     int    21h
  264.  
  265. init_card_1:
  266.  
  267.     mov si, offset board_data    ; address is at start
  268.     mov di, offset curr_hw_addr
  269.     mov cx, EADDR_LEN       ; Copy one address length
  270.     rep     movsb           ; ..
  271.  
  272.     ret
  273.  
  274.     public    print_parameters
  275. print_parameters:
  276. ;echo our command-line parameters
  277.     mov    di,offset int_no
  278.     mov    dx,offset int_no_name
  279.     call    print_number
  280.     mov    di,offset io_addr
  281.     mov    dx,offset io_addr_name
  282.     call    print_number
  283.     ret
  284.  
  285. code    ends
  286.  
  287.     end
  288.